<template>
  <el-dialog :visible="isShow" title="角色分配" @close="closeEvent">
    <el-checkbox-group v-model="roleArr">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div>
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting.js'
import { sysUser } from '@/api/user.js'
import { sysUserassignRoles } from '@/api/employees.js'
export default {
  model: {
    prop: 'isShow'
  },
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      id: '',
      list: [],
      roleArr: []
    }
  },
  // 获取初始化数据
  async created() {
    const res = await sysRole({ page: 1, pagesize: 100 })
    console.log(res, 'mm')
    this.list = res.data.rows
  },
  methods: {
    closeEvent() {
      this.$emit('input', false)
    },
    async getUserInfo(id) {
      this.id = id
      const res = await sysUser(id)
      console.log(res, 'zz')
      this.roleArr = res.data.roleIds
    },
    async submit() {
      await sysUserassignRoles(this.id, this.roleArr)
      this.closeEvent()
    }
  }
}
</script>

<style>

</style>
